/**
 * 
 */
package com.gmail.avereshchaga.db.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.gmail.avereshchaga.db.entity.IDivision;

/**
 * @author <a href="mailto:avereshchaga@gmail.com">Vereshchaga Alexey</a>
 * 
 */

@Repository
public class DivisionDAOImpl implements IDivisionDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public void createDivision(IDivision division) {
        sessionFactory.getCurrentSession().save(division);
    }

    public IDivision readDivision(Long id) {
        return (IDivision) sessionFactory.getCurrentSession().get(
                "com.gmail.avereshchaga.db.entity.DivisionImpl", id);
    }

    public void updateDivivsion(IDivision division) {
        sessionFactory.getCurrentSession().update(division);

    }

    @SuppressWarnings("unchecked")
    public List<IDivision> findAll() {
        return sessionFactory.getCurrentSession()
                .createQuery("from DivisionImpl").list();
    }

    /**
     * @return the sessionFactory
     */
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    /**
     * @param sessionFactory the sessionFactory to set
     */
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

}
